﻿@using hc.epm.UI.Common;
@using hc.epm.DataModel.Basic;
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_LayoutHc.cshtml";
}
<style>
    .btn-group {
        margin-top: 0px !important;
        text-align: left !important;
    }
</style>

<div class="container">
    <div class="row">
        <form class="form-horizontal " id="mainForm">

            <div class="col-lg-12 col-sm-12 form-group" style="margin-bottom:25px">

                <label class="col-lg-2 col-sm-2 control-label"><em class="required">*</em>角色名 : </label>
                <div class="col-lg-10 col-sm-10">
                    <input type="text" name="RoleName" id="RoleName" placeholder="请输入角色名" class="form-control" />
                    <input type="hidden" name="Belong" id="Belong" value="@ViewBag.Belong" />
                </div>

            </div>
            <div class="col-lg-12 col-sm-12 form-group">
                <label class="col-lg-2 col-sm-2 control-label">备注 : </label>
                <div class="col-lg-10 col-sm-10">
                    <textarea name="Remark" rows="5" id="Remark" placeholder="请输入备注" class="form-control"></textarea>
                </div>
            </div>
            <div class="layui-form-item row btn-save  btn-group-position">
                <input type="button" name="save" id="save" lay-submit lay-filter="sub" value="保&nbsp;&nbsp;&nbsp;存" class="layui-btn layui-btn-small button-base bg-save" />
                <input type="button" name="close" value="关&nbsp;&nbsp;&nbsp;闭" class="layui-btn layui-btn-small button-base bg-cancel cancel" />
            </div>

        </form>
    </div>


</div>


<script>

    //自定义验证规则
    window.onload = function () {
        $('#mainForm').bootstrapValidator({
            excluded: [':hidden'],//[':disabled', ':hidden', ':not(:visible)'] //设置隐藏组件可验证
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                RoleName: {
                    validators: {
                        notEmpty: {
                            message: '角色名不能为空'
                        }, stringLength: {
                            max: 500,
                            message: '角色名不能超过500字符'
                        },
                    }
                },
            }
        });
    }
    layui.use(['layer', 'form', 'element'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element;
        //监听提交
        form.on('submit(sub)', function (data) {
            //对表单进行验证
            var bv = $('#mainForm').data('bootstrapValidator');
            bv.validate();
            if (bv.isValid()) {
                var search = $("form").serialize();
                $.post("Add", search, function (data) {
                    if (data.Flag) {
                        layer.msg("角色添加成功", { time: 1000, icon: 1 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);//关闭窗口
                            parent.location.reload();
                        });
                    } else {
                        layer.alert(data.Message, { icon: 2 });
                    }
                });
            };

            return false;

        });
        //关闭弹出iframe层
        $('.cancel').on("click", function () {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);//关闭窗口
        });

    });

</script>
